

class FeatureExtractor:
    def __init__(self, model, layer_id=-1):
        self.feat_ft = None
        self.feat_pre = None
        layer = model.backbone.layers[layer_id]
        layer.register_forward_hook(self.hook_fn)
    
    def hook_fn(self, module, input, output):
        self.feat_ft = output.detach()